package 课堂;

/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author song
 * @date 2017/11/10 14:33
 */
public class 蛮力算法 {
    public static void main(String[] args) {
        int[] a = new int[10];
        for (int p = 0; p < a.length; p++) {
            a[p] = (int) (Math.random() * 10);
        }
        System.out.println(maxSubSequenceSum(a));
        System.out.println(seqStart + "------" + seqEnd);
    }
    static int seqStart = 2;
    static int seqEnd = 5;
    public static int maxSubSequenceSum(int[] a) {
        int maxSum = 0;
        for (int i = 0; i < a.length; i++) {
            for (int j = i; j < a.length; j++) {
                int thisSum = 0;
                for (int k = i; k <= j; k++) {
                    thisSum += a[k];
                }
                if (thisSum > maxSum) {
                    maxSum = thisSum;
                    seqStart = i;
                    seqEnd = j;
                }
            }
        }
        return maxSum;
    }
}
